package com.vhall.component.controller.tag;

import com.vhall.component.controller.tag.facade.TagAdminFacade;
import com.vhall.component.entity.tag.TagEntity;
import com.vhall.component.entity.tag.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.enums.OperateTypeEnum;
import com.vhall.component.service.annotation.OperateLog;
import com.vhall.component.service.tag.TagService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author guoxin.wang
 * @date 2021/7/5 10:35
 */
@Tag(name = "标签管理-管理端")
@VhallComponent
public class TagAdminController implements TagAdminFacade {

    @Autowired
    private TagService tagService;


    @TokenAuth("sys:tag:add")
    @Override
    @OperateLog(type = OperateTypeEnum.CREATE, name = "保存")
    public TagEntity save(TagCreateVO reqVO) {
        return tagService.save(reqVO);
    }

    @TokenAuth("sys:tag:list")
    @Override
    public TagAdminPage<TagEntityVO> list(TagListVO reqVO) {
        TagPage<TagEntityVO> page = tagService.list(reqVO);

        return new TagAdminPage<>(reqVO.getCurrPage(), reqVO.getPageSize(), page.getTotal(), page.getData());
    }

    @TokenAuth("sys:tag:edit")
    @Override
    @OperateLog(type = OperateTypeEnum.UPDATE, name = "更新")
    public Integer update(TagUpdateVO reqVO) {
        return tagService.update(reqVO);
    }

    @TokenAuth("sys:tag:del")
    @Override
    @OperateLog(type = OperateTypeEnum.DELETE, name = "删除")
    public Integer delete(TagDeleteVO reqVO) {
        return tagService.delete(reqVO);
    }

    @Override
    public List<TagEntity> info(TagInfoVO reqVO) {
        return tagService.getInfo(reqVO);
    }

    @TokenAuth("sys:tag:order")
    @Override
    @OperateLog(type = OperateTypeEnum.UPDATE, name = "排序")
    public Boolean order(TagOrderVO reqVO) {
        return tagService.rank(reqVO);
    }
}
